import request from '@/utils/request'
import store from '@/store' // 相当于this.$store
export * from './ArticleDetail/index' // 导入并引出所有

// 用户登录
export const loginAPI = ({ mobile, code }) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

// 频道所有列表
export const allChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'
  })
}

// 获取用户已选
export const yonghusuoxuanAPI = () => {
  return request({
    url: '/v1_0/user/channels'

  })
}

// 更新用户所选
export const gengxinyonghuAPI = ({ channels }) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channels
    }
  })
}

// 获取列表
export const huoquliebiaoAPI = ({ channelId, timestamp }) => {
  return request({
    url: '/v1_0/articles',
    params: {
      // 频道id
      channel_id: channelId,
      // 如果timestamp有,原地用,没有就传null
      // 才会用后面的值
      timestamp: timestamp || new Date().getTime() + ''// 获取时间
    }
  })
}

// 文章 不敢兴趣
export const buganxingquAPI = ({ artId }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: artId
    }
  })
}

// 文章 举报
export const wenzhangjubaoAPI = ({ artId, type }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: {
      target: artId,
      type: type + '',
      // 因为页面没有输入框,如果以后有直接传值,所以这块先传值
      // axios遇到null的值会忽略这对参数
      remark: type === 0 ? '其他问题其他问题啊' : null
    }
  })
}

// 搜索 联想菜单
export const suggestAPI = ({ q }) => {
  return request({
    url: '/v1_0/suggestion',
    params: {
      q
    }
  })
}

// 搜索结果列表
export const searchResultListAPI = ({ q, page = 1 }) => {
  return request({
    url: '/v1_0/search',
    params: {
      q,
      page
    }
  })
}

// 评论  获取列表
export const commentListAPI = ({ artId, offset = null, limit = 10 }) => {
  return request({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: artId,
      offset: offset,
      limit: limit
    }
  })
}

// 评论   喜欢
export const commentLikingAPI = ({ comId }) => {
  return request({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: comId
    }
  })
}

// 评论  取消喜欢
export const commentDisLikingAPI = ({ comId }) => {
  return request({
    url: `/v1_0/comment/likings/${comId}`,
    method: 'DELETE'
  })
}

// 评论 - 发布
export const sendCommentAPI = ({ artId, content }) => {
  return request({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      target: artId,
      content: content
    }
  })
}

// 用户  基本资料
export const userInfoAPI = () => {
  return request({
    url: '/v1_0/user'
  })
}
// 个人资料  为了获取生日
export const userProfileAPI = () => {
  return request({
    url: '/v1_0/user/profile'
  })
}

// 更换头像
// formObj的值必须是一个表单对象
// new FormData()表单对象
export const updatePhotoAPI = (formObj) => {
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: formObj
  })
}

// 用户 - 更新资料
export const updateProfileAPI = ({ birthday, userName }) => {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data: {
      birthday: birthday,
      name: userName
    }
  })
}

// 更新 - token
export const refreshTokenAPI = () => request({
  url: '/v1_0/authorizations',
  method: 'PUT',
  headers: {
    Authorization: `Bearer ${store.state.refresh_token}`
  }
})
